#pragma once

#include <QGraphicsScene>



using namespace std;

class mainClass;
class Node;
class Title;
class Path;
class Sensor;
class Container;
class QGraphicsSceneMouseEvent;
class Text;

class SceneView : public QGraphicsScene
{
	Q_OBJECT

public:
	SceneView(mainClass *_parent);
	mainClass *parent;
	static const enum itemType { NPZ, RVS, AZS, NODE, SENSOR, PATH, TEXT, None};
	Container* addContainer(Container::Type type, QPointF pos, QPointF size = QPointF(-1, -1),
		QString name = "", bool visibleTitle = true);
	Node* addNode(Container *source, QPointF pos, QString name = "", bool visibleTitle = true,
		double _as = 0, double _ad = 0, double _ms = 0, double _md = 0);
	Path* addPath(Node *sourceNode, Node *destNode, QString name = "", bool visibleTitle = true, double leakagePos = -1,
		double _as = 0, double _ad = 0, double _ms = 0, double _md = 0);
	Sensor* addSensor(Path *sourcePath, double percentPos, QString name = "", bool visibleTitle = true, 
		double _as = 0, double _ad = 0, double _ms = 0, double _md = 0);
	Text* addText(QPointF pos, QString name = "");
	vector<Node*> nodeList;
	vector<Path*> pathList;
	vector<Sensor*> sensorList;
	vector<Container *> containerList;
	vector<Text*> textList;
	int selectedPathIndex;
private:
	Path *virtualPath; 
	Node *virtualNode; 
	Container *virtualContainer;
	Sensor *virtualSensor;
	Text * virtualText;
	
	Node *sourceNode;
	bool allowAddVirtualPath, allowRemoveVirtualPath;
	itemType AddVirtualItem;

	bool drawPath;
	QList<Container*> listCopiedContainer;
	void DeleteSensor(Sensor *sensor);
	void DeletePath(Path *path);
	void DeleteNode(Node *node);
	void DeleteContainer(Container *container);
	void DeleteText(Text *text);
	int getPathIndex(Path *_path);
protected:
	void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
	void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
	void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
	void keyPressEvent(QKeyEvent *event);
	void keyReleaseEvent(QKeyEvent *event);
	void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
	void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
	void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
	void dropEvent(QGraphicsSceneDragDropEvent *event);
public slots:
	void dropItem(const QString &name);
	void CopyItem();
	void PasteItem();
	void CutItem();
	void DeleteItem();
	void beginDrawPath();
	void endDrawPath();
	void sendToBack();
	void sendToFront();
	void checkSelectedPath(Path *_path, bool selected);
signals:
	void moveCursor(bool paint, int x = 0, int y = 0);
};
